﻿#!/usr/bin/env python
# ScreenFX.py: screen effects
# 26/05/09
# Copyright(c) 2009 Victor Freire e Cássio Espindola. All rights reserved.
# Python 2.6.2
import random
import pygame

import Sprites
import Defines

class ShieldHitClass:
    def __init__(self):
        self.max_alpha = 90
        self.alpha_inc = 30
        self.alpha_pass_speed = 60
        self.alpha = 0
        self.surface = None
        pass
    
    def new_hit(self):
        self.alpha += self.alpha_inc
        if self.alpha > self.max_alpha:
            self.alpha = self.max_alpha
        
    
    def main(self, dest, mult_factor):
        if not self.surface:
            self.surface = Sprites.Sprites.get_sprite('ui\\playerhit')
        self.surface.set_alpha(self.alpha, pygame.RLEACCEL)
        dest.blit(self.surface, (0, 0))
        self.alpha -= self.alpha_pass_speed * mult_factor
        if self.alpha < 0:
            self.alpha = 0
            
    

ShieldHit = ShieldHitClass()

class BloodDeathClass:
    def __init__(self):
        self.reset()
    
    
    def reset(self):
        self.finished = False
        self.running = True
        self.bloodcolor = (152, 0, 0)
        self.lengths = [0] * Defines.SCREEN_WIDTH
        self.speeds = [random.randint(4,12) for i in xrange(Defines.SCREEN_WIDTH)]
        
        
        
    def draw(self, screen):
        for i in xrange(Defines.SCREEN_WIDTH):
            pygame.draw.line(screen, self.bloodcolor , (i, 0), (i, self.lengths[i]) )
    
    
    def update(self):
        if self.finished: return
        
        updated = False
        for i in xrange(Defines.SCREEN_WIDTH):
            if self.lengths[i] < Defines.SCREEN_HEIGHT:
                updated = True
                self.lengths[i] += self.speeds[i]
                
        if not updated:
            self.finished = True
            self.running = False
            
BloodDeath = BloodDeathClass()
